import { FileManageModel } from "@/models/FileManage/FileManageModel";
import { HttpClient } from "@/utils/HttpClient";


/**
 * 文件管理/上传文件
 */
export class FileManageService {

    /**
 * 上传文件
 * @param dirName 目录名称
 * @param formData 文件内容
 */
    static async uploadAsync(dirName: string, formData: FormData) {
        formData.append("dirName", dirName);
        return await HttpClient.uploadClient<any>("fileManage/upload", formData);
    }

    /**
     * 创建目录
     * @param name 
     * @returns 
     */
    static async createDirectoryAsync(name: string) {
        return await HttpClient.post("fileManage/createDirectory", { name: name });
    }

    /**
     * 获取目录
     * @returns 
     */
    static async directoryListAsync() {
        //return await HttpClient.postAsResult<FileManageModel.Directory[]>("fileManage/directoryList", {});

        let data: FileManageModel.Directory[] = [];

        for (let index = 0; index < 6; index++) {
            data.push({
                id: index + 1,
                dirName: "name_" + (index + 1)
            });
        }

        return await new Promise<FileManageModel.Directory[]>((resolve, reject) => {

            resolve(data);
        });
    }

    /**
     * 获取文件信息
     * @param marker 
     * @param dirName 
     * @returns 
     */
    static async fileListAsync(marker: string, dirName: string) {
        //  return await HttpClient.postAsResult<FileManageModel.File>("fileManage/fileList", { marker: marker, dirName: dirName });

        let data: FileManageModel.File = {
            url: [
                "https://img2.woyaogexing.com/2022/07/01/91205801e0245ceb!400x400.jpg",
                "https://img2.woyaogexing.com/2022/07/01/456101da549bd659!400x400.jpg",
                "https://img2.woyaogexing.com/2022/07/01/3aeb8f0b712dc3b7!400x400.jpg",
                "https://img2.woyaogexing.com/2022/07/01/4cbe61fe79e4a609!400x400.jpg",
                "https://img2.woyaogexing.com/2022/07/01/fe63dcb7ced3e7ae!400x400.jpg",
                "https://img2.woyaogexing.com/2022/07/01/8f9d90a8a1ab93ce!400x400.jpg"
            ],
            nextMarker: ""
        };
        return await new Promise<FileManageModel.File>((resolve, reject) => {
            resolve(data);
        });

    }

}
